﻿Public Class frmMaxiFileResult

    Private Sub cmbFile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbFile.Click

    End Sub

    Private Sub cmbFile_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmbFile.SelectedIndexChanged
        Dim index As Integer = cmbFile.SelectedIndex
        If index >= 0 Then
            Dim MaxiFile As CAermod.MaxiFile = AermodProject0.Aermod.OutPutOption.ArrayMaxiFile(index)
            Me.txtFileName.Text = "文件信息：污染物为[" & MaxiFile.PolluteName & "]，污染源分组为[" & MaxiFile.GroupName _
                                & "]，平均时间为[" & MaxiFile.AervarageTime & "]，浓度限值为[" & MaxiFile.Maxi & "mg/m^3]" _
                                & "。文件名和路径为[" & MaxiFile.FileName & "]"
            ShowData(MaxiFile.FileName)
        End If
    End Sub
    Private Sub ShowData(ByVal strMaxiFileName As String)
        Try
            If Not strMaxiFileName.Contains(":") Then '如果是相对路径
                strMaxiFileName = CAermod.Path.ModelsPath & strMaxiFileName
            End If
            Dim MaxiFileData(-1) As String
            Dim strLine As String
            Try
                FileOpen(1, strMaxiFileName, OpenMode.Input) '打开文件
                Do Until EOF(1)
                    strLine = LineInput(1) '读取一行
                    ReDim Preserve MaxiFileData(MaxiFileData.Length)
                    MaxiFileData(MaxiFileData.Length - 1) = strLine
                Loop
                FileClose(1) '关闭文件
            Catch ex As Exception
                MessageBox.Show(ex.Message)
                MessageBox.Show("数据文件出错，请检查数据文件的格式!")
                FileClose(1) '关闭文件
                Exit Sub
            Finally
                FileClose(1) '关闭文件
            End Try
            EFlex1.AutoSizeCols()
            EFlex1.Rows.Count = 1
            '从文件中读取数据
            Dim nCol As Integer = 0 '用于记列数
            Dim RowPage As Integer = 0 '用于标记行的页数
            Dim ColPage As Integer = 0 '用于标记列的页数
            For nAllString As Integer = 0 To MaxiFileData.Length - 1
                strLine = MaxiFileData(nAllString) '读取一行
                If Not strLine.Contains("*") Then
                    Dim strDate As String = strLine.Substring(14, 8)
                    Dim x As Double = strLine.Substring(24, 12)
                    Dim y As Double = strLine.Substring(38, 12)
                    Dim con As Double = strLine.Substring(76, 12) / 1000
                    EFlex1.Rows.Count += 1
                    EFlex1.SetData(EFlex1.Rows.Count - 1, 0, EFlex1.Rows.Count - 1)
                    EFlex1.SetData(EFlex1.Rows.Count - 1, 1, strDate)
                    EFlex1.SetData(EFlex1.Rows.Count - 1, 2, x)
                    EFlex1.SetData(EFlex1.Rows.Count - 1, 3, y)
                    EFlex1.SetData(EFlex1.Rows.Count - 1, 4, FormatNumber(con, 9))
                End If
            Next
            EFlex1.AutoSizeCols()
        Catch ex As Exception
            MessageBox.Show("预测方案可能已经被改变，请重新计算!")
        End Try

    End Sub

    Private Sub frmMaxiFileResult_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.EFlex1.Styles.Alternate.BackColor = Color.FromArgb(216, 228, 248)
        '设置列数及行标题
        EFlex1.Cols.Count = 15
        EFlex1.AllowSorting = C1.Win.C1FlexGrid.AllowSortingEnum.None
        EFlex1.AllowResizing = C1.Win.C1FlexGrid.AllowResizingEnum.Columns
        EFlex1.AllowDragging = C1.Win.C1FlexGrid.AllowDraggingEnum.None
        EFlex1.AllowMerging = C1.Win.C1FlexGrid.AllowMergingEnum.None
        For i As Integer = 0 To 2
            Me.EFlex1.Cols(i).AllowMerging = True
        Next
        EFlex1.SetData(0, 0, "序号")
        EFlex1.SetData(0, 1, "出现时刻")
        EFlex1.SetData(0, 2, "x")
        EFlex1.SetData(0, 3, "x")
        EFlex1.SetData(0, 4, "浓度值[mg/m^3]")
    End Sub


End Class